/*
    Copyright 2007-2008 Christian Henning, Andreas Pokorny, Lubomir Bourdev
    Use, modification and distribution are subject to the Boost Software License,
    Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
    http://www.boost.org/LICENSE_1_0.txt).
*/

/*************************************************************************************************/

#ifndef BOOST_GIL_EXTENSION_IO_DETAIL_BASE_HPP_INCLUDED
#define BOOST_GIL_EXTENSION_IO_DETAIL_BASE_HPP_INCLUDED

////////////////////////////////////////////////////////////////////////////////////////
/// \file
/// \brief
/// \author Christian Henning, Andreas Pokorny, Lubomir Bourdev \n
///
/// \date   2007-2008 \n
///
////////////////////////////////////////////////////////////////////////////////////////

#include <ostream>
#include <istream>
#include <vector>

#include <boost/array.hpp>
#include <boost/bind.hpp>
#include <boost/type_traits/is_base_of.hpp>

#include <boost/gil/utilities.hpp>
#include <boost/gil/color_convert.hpp>
#include <boost/gil/bit_aligned_pixel_reference.hpp>
#include <boost/gil/bit_aligned_pixel_iterator.hpp>

#include "typedefs.hpp"
#include "gil_extensions.hpp"

namespace boost
{
namespace gil
{

struct format_tag {};

template< typename Property >
struct property_base
{
    typedef Property type;
};

template<typename FormatTag> struct is_format_tag : is_base_and_derived< format_tag
            , FormatTag
            > {};

struct image_read_settings_base
{
protected:

    image_read_settings_base()
            : _top_left( 0, 0 )
            , _dim     ( 0, 0 )
    {}

    image_read_settings_base( const point_t& top_left
                              , const point_t& dim
                            )
            : _top_left( top_left )
            , _dim     ( dim      )
    {}

public:

    point_t _top_left;
    point_t _dim;
};

/**
 * Boolean meta function, mpl::true_ if the pixel type \a PixelType is supported
 * by the image format identified with \a FormatTag.
 * \todo the name is_supported is to generic, pick something more IO realted.
 */
// Depending on image type the parameter Pixel can be a reference type
// for bit_aligned images or a pixel for byte images.
template< typename Pixel, typename FormatTag > struct is_read_supported {};
template< typename Pixel, typename FormatTag > struct is_write_supported {};


namespace detail
{

template< typename Property >
struct property_base
{
    typedef Property type;
};


inline
void io_error( const std::string& descr )
{
    throw std::ios_base::failure( descr );
}

inline
void io_error_if( bool expr, const std::string& descr )
{
    if ( expr )
        io_error( descr );
}

struct read_support_true
{
    BOOST_STATIC_CONSTANT( bool, is_supported = true );
};
struct read_support_false
{
    BOOST_STATIC_CONSTANT( bool, is_supported = false );
};
struct write_support_true
{
    BOOST_STATIC_CONSTANT( bool, is_supported = true );
};
struct write_support_false
{
    BOOST_STATIC_CONSTANT( bool, is_supported = false );
};

class no_log {};

} // namespace detail

template<typename FormatTag> struct image_read_info;
template<typename FormatTag> struct image_read_settings;
template<typename FormatTag, typename Log = typename detail::no_log > struct image_write_info;

} // namespace gil
} // namespace boost

#endif // BOOST_GIL_EXTENSION_IO_DETAIL_BASE_HPP_INCLUDED
